<?php

namespace app\api\controller;


use think\Cache;

class Banner extends ApiBase {
    public function _initialize() {
        $bannerTimeLine = Cache::get('bannerTimeLine');
        if ($bannerTimeLine) {
            return;
        }
        $banners = model('Banner')
            ->where('status', 'neq', config('code.status_delete'))
            ->field('id,expert,status')
            ->select();
        $now     = time();
        foreach ($banners as $banner) {
            $expert = $banner->expert;
            if ($now > $expert && $banner->status != 2) {
                $banner->status = 2;
                $banner->save();
            }
        }
        Cache::set('bannerTimeLine', '2个小时', config('setting.token_expire_in'));
    }

    public function index() {
        validate('Banner')->goCheck('xcx');
        $query                    = input('get.');
        $condition['status']      = config('code.status_show');
        $condition['position_id'] = ['in', $query['position_ids']];
        $result                   = model('Banner')->getBanners($condition);
        return show(config('code.success'), '获取数据成功', $result);
    }

    public function read() {

    }
}